import { defineStore } from 'pinia'
import { ref } from 'vue'
import { userGetInfoService } from '@/api/login/user'
export const useUserStore = defineStore(
  'qd-user',
  () => {
    // token
    const token = ref('')
    const getToken = () => {
      return token.value
    }
    const setToken = (newToken) => {
      token.value = newToken
    }

    // 用户信息
    const info = ref({})

    const getInfo = async () => {
      const res = await userGetInfoService()
      info.value = res.data
    }

    const setInfo = (obj) => {
      info.value = obj
    }

    return {
      token,
      getToken,
      setToken,
      info,
      getInfo,
      setInfo
    }
  },
  {
    persist: true
  }
)
